/**
 * 内容管理管理初始化
 */
var TBusiness = {
    id: "TBusinessTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
TBusiness.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: 'id', field: 'id', visible: true, align: 'center', valign: 'middle'},
            {title: '排序', field: 'seq', visible: true, align: 'center', valign: 'middle'},
            {title: '标题', field: 'title', visible: true, align: 'center', valign: 'middle'},
            {title: '按钮文字', field: 'btnText', visible: true, align: 'center', valign: 'middle'},
            {title: '图片', field: 'imageSrc', visible: true, align: 'center', valign: 'middle', formatter: function (value, row, index) {
          	  var e = '<img src='+row.imageSrc+' width=\'32px\' height=\"32px\">';
        	  return e;
            }},
            {title: '跳转类型', field: 'jumpType', visible: true, align: 'center', valign: 'middle'},
            {title: 'appId', field: 'appId', visible: true, align: 'center', valign: 'middle'},
            {title: '小程序页面', field: 'appUrl', visible: true, align: 'center', valign: 'middle'},
            {title: 'h5页面', field: 'h5Url', visible: true, align: 'center', valign: 'middle'},
    ];
};

/**
 * 检查是否选中
 */
TBusiness.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        TBusiness.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加内容管理
 */
TBusiness.openAddTBusiness = function () {
	
    var appId = localStorage.getItem("appid");//获取存储的变量key的值 
    
    var index = layer.open({
        type: 2,
        title: '添加内容管理',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/tBusiness/tBusiness_add?appId='+appId
    });
    this.layerIndex = index;
};

/**
 * 打开查看内容管理详情
 */
TBusiness.openTBusinessDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '内容管理详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/tBusiness/tBusiness_update/' + TBusiness.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除内容管理
 */
TBusiness.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/tBusiness/delete", function (data) {
            Feng.success("删除成功!");
            TBusiness.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("tBusinessId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询内容管理列表
 */
TBusiness.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    TBusiness.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = TBusiness.initColumn();
    var table = new BSTable(TBusiness.id, "/tBusiness/list", defaultColunms);
    table.setPaginationType("client");
    var appid = localStorage.getItem("appid");//获取存储的变量key的值 
    var params={"appid":appid};
    table.setQueryParams(params);
    TBusiness.table = table.init();
});
